Fix wc_CmacFree() to use correct heap pointer from internal Aes structure #9527
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix CMAC heap pointer reference in wc_CmacFree() and wc_CMAC_Grow()
Issue
The
wc_CmacFree()function was attempting to accesscmac->heapwhich does not exist in theCmacstructure, thus causing a compile failure. Additionally,wc_CMAC_Grow()was passingNULLfor the heap parameter, creating an pointer mismatch if the heap is non NULL. TheCmacstructure contains anAesmember, and it is theAesstructure that has theheapfield.How to Reproduce
./autogen.sh ./configure --enable-cmac CFLAGS="-DWOLFSSL_HASH_KEEP" makeContext: How heap is initialized
In
wc_InitCmac_ex()(line 149: cmac.c), the heap parameter is passed towc_AesInit():This stores the heap pointer in
cmac->aes.heap. So when allocating/freeing CMAC memory, we should usecmac->aes.heapto ensure we're using the same heap pointer throughout the CMAC lifecycle.Fix
Two changes in
wolfcrypt/src/cmac.c:wc_CMAC_Grow(): ChangedNULLtocmac->aes.heapwhen calling_wc_Hash_Grow()to ensure allocation uses the correct heapwc_CmacFree(): Changedcmac->heaptocmac->aes.heapto use the correct heap pointer for deallocation